package persentation.presentAdministrator;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;

import javax.swing.DefaultCellEditor;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.border.BevelBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;

import vo.courseVO.CourseVO;
import vo.userVO.DepartmentDeanVO;
import vo.userVO.StudentVO;
import vo.userVO.TeacherVO;
import vo.userVO.UniversityDeanVO;
import vo.userVO.UserVO;
import businesslogic.chooseCourseBl.ChooseCourseController;
import businesslogic.courseBl.CourseController;
import businesslogic.userBl.Administrator;
import businesslogic.userBl.AdministratorController;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JComboBox;

import dataservice.ResultMessage;

import javax.swing.table.TableCellEditor;
public class ShowUserPanel extends JPanel{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ArrayList<UserVO> userList;
	private ArrayList<StudentVO> studentList;
	private ArrayList<TeacherVO> teacherList;
	private ArrayList<DepartmentDeanVO> departmentDeanList;
	private ArrayList<UniversityDeanVO> universityDeanList;
	private JTable studentTable;
	
	private JTable teacherTable;
	private JTable departmentDeanTable;
	private JTable universityDeanTable;
	private DefaultTableModel model;
	private JComboBox<String> userTypeBox;
	private JComboBox<String> departmentBox;
	private JScrollPane scrollPane;
	private MyTabbedPane tabbedPane;
	
	private int userType;
	private JPanel addUserPanel;
	
	private String departmentID="全部";
	private String []departmentList=new String[29];
	
	
	private String []departmentString=new  String[28];
	
	private final Integer[] grades={1,2,3,4};
	
	private AdministratorController administratorController=new AdministratorController();
	private JButton button;
	private JButton button_1;
	
	
	public class TableStyle extends DefaultTableCellRenderer{  
	    public TableStyle(){  
	        setHorizontalAlignment(RIGHT);  
	    } 
	} 

	/**
	 * Create the panel.
	 */
	
	public ShowUserPanel(CourseController courseController) {
		

		
		
		setSize(800, 600);
		setLayout(null);
		
		ArrayList<String> departmentArrayList;
		try {
			departmentArrayList = courseController.getAllDepartments();
			departmentList[0]="全部";
			for (int i = 0; i<departmentArrayList.size(); i++) {
				departmentList[i+1]=departmentArrayList.get(i);
				departmentString[i]=departmentArrayList.get(i);
			}
		} catch (Exception e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}
		
		final DefaultCellEditor stringEditor=new DefaultCellEditor(new JTextField());
		
		
		
		
		
		
		scrollPane = new JScrollPane();
		scrollPane.setBounds(37, 93, 712, 384);

		JComboBox gradeBox=new JComboBox(grades);
		JComboBox departBox=new JComboBox(departmentString);
		final DefaultCellEditor gradeEditor=new DefaultCellEditor(gradeBox);
		final DefaultCellEditor departmentEditor=new DefaultCellEditor(departBox);
		
		this.add(scrollPane);
		
		studentTable = new JTable(new DefaultTableModel(
				new Object[][] {
						
				},
				new String[] {
						 "用户ID","用户名","年级","院系名称","重置用户密码"
				}
			) 
			{
				/**
				 * 
				 */
				private static final long serialVersionUID = 1L;
				Class[] columnTypes = new Class[] {
					String.class, String.class,Integer.class,String.class,String.class
				};
				public Class getColumnClass(int columnIndex) {
					return columnTypes[columnIndex];
				}
			}){
			
			public TableCellEditor getCellEditor(int row, int column)
            {
                int modelColumn = convertColumnIndexToModel( column );

                if (modelColumn == 2)
                    return (TableCellEditor) gradeEditor;
                if(modelColumn==3)
                	return (TableCellEditor)departmentEditor;
                	
                else {
					return stringEditor;
				}
            } 
			
		};
		
		studentTable.setFont(new Font("微软雅黑", Font.PLAIN, 13));
//		studentTable.setModel(new DefaultTableModel(
//			new Object[][] {
//				
//			},
//			new String[] {
//					 "用户ID","用户名","年级","院系名称","重置用户密码"
//			}
//		) 
//		{
//			/**
//			 * 
//			 */
//			private static final long serialVersionUID = 1L;
//			Class[] columnTypes = new Class[] {
//				String.class, String.class,Integer.class,String.class,String.class
//			};
//			public Class getColumnClass(int columnIndex) {
//				return columnTypes[columnIndex];
//			}
//		});

		
		scrollPane.setViewportView(studentTable);

		studentTable.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseExited(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseEntered(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseClicked(MouseEvent e) {
				if(studentTable.getSelectedRow()!=-1)
					button.setEnabled(true);
			}
		});
		studentTable.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		studentTable.getTableHeader().setReorderingAllowed(false);
		studentTable.getTableHeader().setResizingAllowed(false);
		studentTable.setDefaultRenderer(Object.class,new TableStyle());
		
		
		teacherTable = new JTable(){
			public TableCellEditor getCellEditor(int row, int column)
            {
                int modelColumn = convertColumnIndexToModel( column );

                if (modelColumn == 2)
                    return (TableCellEditor) departmentEditor;
                else {
					return stringEditor;
				}
            } 
		};
		teacherTable.setFont(new Font("微软雅黑", Font.PLAIN, 13));
		teacherTable.setModel(new DefaultTableModel(
			new Object[][] {
				
			},
			new String[] {
					 "用户ID","用户名","院系名称","重置用户密码"
			}
		) 
		{
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;
			Class[] columnTypes = new Class[] {
				String.class, String.class,String.class,String.class
			};
			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
		});

//		scrollPane.setViewportView(teacherTable);
		teacherTable.setDefaultRenderer(Object.class,new TableStyle());
		teacherTable.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseExited(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseEntered(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseClicked(MouseEvent e) {
				if(teacherTable.getSelectedRow()!=-1)
					button.setEnabled(true);
			}
		});
		teacherTable.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		teacherTable.getTableHeader().setReorderingAllowed(false);
		teacherTable.getTableHeader().setResizingAllowed(false);
//		teacherTable.setVisible(false);
		
		departmentDeanTable = new JTable(){
			public TableCellEditor getCellEditor(int row, int column)
            {
                int modelColumn = convertColumnIndexToModel( column );

                if (modelColumn == 2)
                    return (TableCellEditor) departmentEditor;
                else {
					return stringEditor;
				}
            } 
		};
		departmentDeanTable.setDefaultRenderer(Object.class,new TableStyle());
		departmentDeanTable.setFont(new Font("微软雅黑", Font.PLAIN, 13));
		departmentDeanTable.setModel(new DefaultTableModel(
			new Object[][] {
				
			},
			new String[] {
					 "用户ID","用户名","院系名称","重置用户密码"
			}
		) 
		{
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;
			Class[] columnTypes = new Class[] {
				String.class, String.class,String.class,String.class
			};
			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
		});

//		scrollPane.setViewportView(departmentDeanTable);

		departmentDeanTable.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseExited(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseEntered(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseClicked(MouseEvent e) {
				if(departmentDeanTable.getSelectedRow()!=-1)
					button.setEnabled(true);
				
			}
		});
		departmentDeanTable.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		departmentDeanTable.getTableHeader().setReorderingAllowed(false);
		departmentDeanTable.getTableHeader().setResizingAllowed(false);
//		departmentDeanTable.setVisible(false);
		
		
		universityDeanTable = new JTable(){
			public TableCellEditor getCellEditor(int row, int column)
            {
                
					return stringEditor;
				
            } 
		};
		universityDeanTable.setDefaultRenderer(Object.class,new TableStyle());
		universityDeanTable.setFont(new Font("微软雅黑", Font.PLAIN, 13));
		universityDeanTable.setModel(new DefaultTableModel(
			new Object[][] {
				
			},
			new String[] {
					 "用户ID","用户名","重置用户密码"
			}
		) 
		{
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;
			Class[] columnTypes = new Class[] {
				String.class, String.class,String.class
			};
			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
		});

		

		universityDeanTable.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseExited(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseEntered(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseClicked(MouseEvent e) {
				if(universityDeanTable.getSelectedRow()!=-1)
					button.setEnabled(true);
				
			}
		});
		universityDeanTable.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		universityDeanTable.getTableHeader().setReorderingAllowed(false);
		universityDeanTable.getTableHeader().setResizingAllowed(false);
//		universityDeanTable.setVisible(false);
		
		try {
			userList=administratorController.getUserList(0, "全部");
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			ExceptionHandler.networkException();
		}
		fillStudentTable();
		
		JLabel lblNewLabel = new JLabel("用户类型");
		lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		lblNewLabel.setBounds(48, 26, 127, 38);
		add(lblNewLabel);
		
		userTypeBox = new JComboBox();
		userTypeBox.setModel(new DefaultComboBoxModel<String>(new String[]{"学生","任课教师","院系教务老师","教务处老师"}));
		userTypeBox.setBounds(190, 30, 177, 30);
		add(userTypeBox);
		
		JLabel label = new JLabel("院系名称");
		label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		
		label.setBounds(423, 26, 87, 38);
		add(label);
		
		departmentBox = new JComboBox();
		departmentBox.setFont(new Font("微软雅黑", Font.PLAIN, 18));
		departmentBox.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				if (e.getStateChange()==ItemEvent.SELECTED) {
					departmentID=departmentBox.getSelectedItem().toString();
					fillTable();
				}
			}
		});
		departmentBox.setModel(new DefaultComboBoxModel(departmentList));
		departmentBox.setBounds(542, 30, 177, 30);
		add(departmentBox);
		userTypeBox.setFont(new Font("微软雅黑", Font.PLAIN, 18));
//		userTypeBox.addItemListener(new ItemListener() {
//			
//			@Override
//			public void itemStateChanged(ItemEvent e) {
//				if(e.getStateChange()==ItemEvent.SELECTED)
//					userType=userTypeBox.getSelectedIndex();	
//				
//					fillTable();
//			}
//		});
		userTypeBox.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				if(userTypeBox.getSelectedIndex()==3){
					departmentBox.setSelectedIndex(0);
					departmentBox.setEditable(false);
					
					
				}
					
				
				userType=userTypeBox.getSelectedIndex();	
				
				fillTable();
			}
		});
		
		
		button = new JButton("修改用户信息");
		button.setEnabled(false);
		button.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				int message=JOptionPane.showConfirmDialog(null,"确认修改用户信息？","确认",JOptionPane.YES_NO_OPTION);
				if(message==JOptionPane.YES_OPTION){
					ResultMessage m=sendRequest();
					if(m==ResultMessage.UPDATE_SUCCESS){
						JOptionPane.showMessageDialog(null,"用户信息修改成功！","提示",JOptionPane.INFORMATION_MESSAGE);

						fillTable();
						setEnabled(false);
					}
					else {
						JOptionPane.showMessageDialog(null,"用户信息修改失败！","提示",JOptionPane.INFORMATION_MESSAGE);
					
						fillTable();
						setEnabled(false);

					}
				}
				
			}
		});
		button.setFont(new Font("微软雅黑", Font.PLAIN, 18));
		button.setBounds(208, 487, 141, 38);
		add(button);
		
		button_1 = new JButton("取         消");
		button_1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				int message=JOptionPane.showConfirmDialog(null,"取消查看和修改？","确认",JOptionPane.YES_NO_OPTION);
				if(message==JOptionPane.YES_OPTION){
					tabbedPane.removeTabAt(tabbedPane.indexOfTab("查看用户信息"));
//					tabbedPane.removeOne(tabbedPane.indexOfTab("查看用户信息"));
				}
				
			}
		});
		button_1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
		button_1.setBounds(459, 487, 141, 38);
		add(button_1);
		
		
		
		
//		table.setBackground(new Color(135, 206, 250));
//		table.add(table.getTableHeader());
		
//		fillTable();

	}
	
	public void fillStudentTable(){
//		studentTable.setVisible(true);
//		teacherTable.setVisible(false);
//		departmentDeanTable.setVisible(false);
//		universityDeanTable.setVisible(false);
		scrollPane.setViewportView(studentTable);
		DefaultTableModel tableModel = (DefaultTableModel) studentTable.getModel();
		 tableModel.setRowCount(0);
		 try {
			userList=administratorController.getUserList(userType, departmentID);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			ExceptionHandler.networkException();
		}
		 
		 for(UserVO userVO:userList){
			 StudentVO studentVO=(StudentVO)userVO;
			 Object[] array=new Object [4];
			 array[0]=studentVO.getId();
			 array[1]=studentVO.getName();
			 array[2]=studentVO.getGrade();
			 array[3]=studentVO.getDepartmentId();
//			 array[4]=studentVO.getGPA();
//			 array[4]=studentVO.getId();
			 
			
			
			 System.out.println(array[0]);
			 System.out.println(array[1]);
			 System.out.println(array[2]);
			 tableModel.addRow(array);
			 studentTable.invalidate();
			 studentTable.updateUI();
	      }
	} 
	
	public void fillTeacherTable(){
//		studentTable.setVisible(false);
//		teacherTable.setVisible(true);
//		departmentDeanTable.setVisible(false);
//		universityDeanTable.setVisible(false);
		scrollPane.setViewportView(teacherTable);
		DefaultTableModel tableModel = (DefaultTableModel) teacherTable.getModel();
		 tableModel.setRowCount(0);
		 try {
			userList=administratorController.getUserList(userType, departmentID);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			ExceptionHandler.networkException();
		}
		 
		 for(UserVO userVO:userList){
			 TeacherVO teacherVO=(TeacherVO)userVO;
			 Object[] array=new Object [3];
			 array[0]=teacherVO.getId();
			 array[1]=teacherVO.getName();
			 
			 array[2]=teacherVO.getDepartmentId();
			 
//			 array[3]=teacherVO.getId();
			 
			
			
			 System.out.println(array[0]);
			 System.out.println(array[1]);
			 System.out.println(array[2]);
			 tableModel.addRow(array);
			 teacherTable.invalidate();
			 teacherTable.updateUI();
	      }
	} 
	
	public void fillDepartmentDeanTable(){
//		studentTable.setVisible(false);
//		teacherTable.setVisible(false);
//		departmentDeanTable.setVisible(true);
//		universityDeanTable.setVisible(false);
		scrollPane.setViewportView(departmentDeanTable);
		DefaultTableModel tableModel = (DefaultTableModel) departmentDeanTable.getModel();
		 tableModel.setRowCount(0);
		 try {
			userList=administratorController.getUserList(userType, departmentID);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			ExceptionHandler.networkException();
		}
		 
		 for(UserVO userVO:userList){
			 DepartmentDeanVO departmentDeanVO=(DepartmentDeanVO)userVO;
			 Object[] array=new Object [3];
			 array[0]=departmentDeanVO.getId();
			 array[1]=departmentDeanVO.getName();
			 
			 array[2]=departmentDeanVO.getDepartmentId();
			 
//			 array[3]=departmentDeanVO.getId();
			 
			
			
			 System.out.println(array[0]);
			 System.out.println(array[1]);
			 System.out.println(array[2]);
			 System.out.println("erboereorwarjpfjasjfasifjashfaospifhjasfasdfsafsddfas");
			 tableModel.addRow(array);
			 departmentDeanTable.invalidate();
			 departmentDeanTable.updateUI();
	      }
	}
		 
		 
		 public void fillUniversityDeanTable(){
//			 	studentTable.setVisible(false);
//				teacherTable.setVisible(false);
//				departmentDeanTable.setVisible(false);
//				universityDeanTable.setVisible(true);
			 	scrollPane.setViewportView(universityDeanTable);
				DefaultTableModel tableModel = (DefaultTableModel) universityDeanTable.getModel();
				 tableModel.setRowCount(0);
				 try {
					userList=administratorController.getUserList(userType, departmentID);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					ExceptionHandler.networkException();
				}
				 
				 for(UserVO userVO:userList){
					 UniversityDeanVO universityDeanVO=(UniversityDeanVO)userVO;
					 Object[] array=new Object [2];
					 array[0]=universityDeanVO.getId();
					 array[1]=universityDeanVO.getName();
					 
					 
					 
//					 array[2]=universityDeanVO.getId();
					 
					
					
					 System.out.println(array[0]);
					 System.out.println(array[1]);
//					 System.out.println(array[2]);
					 tableModel.addRow(array);
					 universityDeanTable.invalidate();
					 universityDeanTable.updateUI();
			      }
	} 
		 
		 
		 
	public void fillTable(){
		switch (userType) {
			case 0:
				fillStudentTable();
				
				break;

			case 1:
				fillTeacherTable();
				break;
			case 2:
				fillDepartmentDeanTable();
	
				break;
			case 3:
	
				fillUniversityDeanTable();
				break;
			}
	 }
	
	public ResultMessage modifyStudent(){
		ArrayList<ResultMessage> messages=new ArrayList<>();
		ResultMessage resultMessage=ResultMessage.UPDATE_SUCCESS;
		
		for(int i=0;i<studentTable.getRowCount();i++){
			
			
			
			if(studentTable.getValueAt(i, 0)==null||studentTable.getValueAt(i, 1)==null||studentTable.getValueAt(i, 2)==null||studentTable.getValueAt(i, 3)==null)
			
				return ResultMessage.UPDATE_FAILURE;
			String id=studentTable.getValueAt(i, 0).toString().trim();
			String name=studentTable.getValueAt(i, 1).toString().trim();
			String departmentId=studentTable.getValueAt(i, 3).toString().trim();
			int grade= Integer.parseInt(studentTable.getValueAt(i, 2).toString());
			System.out.println("OOOOOOOOOOOOOOOOOOOO"+grade);
			ResultMessage msg;
			try {
				msg = administratorController.modifyUser(new StudentVO(id,name,departmentId,grade));
			
				messages.add(msg);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				ExceptionHandler.networkException();
			}
			
			
			
			if(studentTable.getValueAt(i, 4)!=null){
				String password=studentTable.getValueAt(i, 4).toString().trim();
				try {
					administratorController.modifyPassword(id, password);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					ExceptionHandler.networkException();
				}

			}
				
			
		}
		
		for(ResultMessage message:messages)
			if(message!=ResultMessage.UPDATE_SUCCESS)
			
				resultMessage=ResultMessage.UPDATE_FAILURE;
			
		
			
		return resultMessage;
	}
	
	public ResultMessage modifyTeacher(){
		ArrayList<ResultMessage> messages=new ArrayList<>();
		ResultMessage resultMessage=ResultMessage.UPDATE_SUCCESS;
		
		for(int i=0;i<teacherTable.getRowCount();i++){
			System.out.println("****************************************************************");
			System.out.println(			(teacherTable.getValueAt(i, 0)==null||teacherTable.getValueAt(i, 1)==null||teacherTable.getValueAt(i, 2)==null)
);
			if(teacherTable.getValueAt(i, 0)==null||teacherTable.getValueAt(i, 1)==null||teacherTable.getValueAt(i, 2)==null){
				return ResultMessage.UPDATE_FAILURE;

				
			}
				
			
				
			
			String id=teacherTable.getValueAt(i, 0).toString().trim();
			String name=teacherTable.getValueAt(i, 1).toString().trim();
			String departmentId=teacherTable.getValueAt(i, 2).toString().trim();
			
			ResultMessage msg;
			try {
				msg = administratorController.modifyUser(new TeacherVO(id, name, departmentId));
			
				messages.add(msg);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				ExceptionHandler.networkException();
			}
			
			
			
			if(teacherTable.getValueAt(i, 3)!=null){
				String password=teacherTable.getValueAt(i, 3).toString().trim();
				try {
					administratorController.modifyPassword(id, password);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					ExceptionHandler.networkException();
				}
			}
				
			
		}
		
		for(ResultMessage message:messages)
			if(message!=ResultMessage.UPDATE_SUCCESS)
			
				resultMessage=ResultMessage.UPDATE_FAILURE;
			
		
			System.out.println("*****************"+resultMessage);
		return resultMessage;
	}
	public ResultMessage modifyDepartmentDean(){
		ArrayList<ResultMessage> messages=new ArrayList<>();
		ResultMessage resultMessage=ResultMessage.UPDATE_SUCCESS;
		
		for(int i=0;i<departmentDeanTable.getRowCount();i++){
			
			
			if(departmentDeanTable.getValueAt(i, 0)==null||departmentDeanTable.getValueAt(i, 1)==null||departmentDeanTable.getValueAt(i, 2)==null)
				
				return ResultMessage.UPDATE_FAILURE;
			String id=departmentDeanTable.getValueAt(i, 0).toString().trim();
			String name=departmentDeanTable.getValueAt(i, 1).toString().trim();
			String departmentId=departmentDeanTable.getValueAt(i, 2).toString().trim();
			
			ResultMessage msg;
			try {
				msg = administratorController.modifyUser(new DepartmentDeanVO(id, name, departmentId));
			
				messages.add(msg);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
			
			if(departmentDeanTable.getValueAt(i, 3)!=null){
				String password=departmentDeanTable.getValueAt(i, 3).toString().trim();
			
				try {
					administratorController.modifyPassword(id, password);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					ExceptionHandler.networkException();
				}

			}
			
		}
		
		for(ResultMessage message:messages)
			if(message!=ResultMessage.UPDATE_SUCCESS)
			
				resultMessage=ResultMessage.UPDATE_FAILURE;
			
		
			
		return resultMessage;
	}
	public ResultMessage modifyUniversityDean(){
		ArrayList<ResultMessage> messages=new ArrayList<>();
		ResultMessage resultMessage=ResultMessage.UPDATE_SUCCESS;
		
		for(int i=0;i<universityDeanTable.getRowCount();i++){
			
			if(universityDeanTable.getValueAt(i, 0)==null||universityDeanTable.getValueAt(i, 1)==null)
				
				return ResultMessage.UPDATE_FAILURE;
			
			String id=universityDeanTable.getValueAt(i, 0).toString().trim();
			String name=universityDeanTable.getValueAt(i, 1).toString().trim();
			
			
			ResultMessage msg;
			try {
				msg = administratorController.modifyUser(new UniversityDeanVO(id, name));
				messages.add(msg);
				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				ExceptionHandler.networkException();
			}
			
			
			if(universityDeanTable.getValueAt(i, 2)!=null){
				String password=universityDeanTable.getValueAt(i, 2).toString().trim();
				try {
					administratorController.modifyPassword(id, password);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					ExceptionHandler.networkException();
				}
			}
				
			
		}
		
		for(ResultMessage message:messages)
			if(message!=ResultMessage.UPDATE_SUCCESS)
			
				resultMessage=ResultMessage.UPDATE_FAILURE;
			
		
			
		return resultMessage;
	}
	
	public ResultMessage sendRequest(){
		ResultMessage message=null;
		switch (userType) {
		case 0:
			 message=modifyStudent();
			

		case 1:
			 message=modifyTeacher();
			
		case 2:
			 message=modifyDepartmentDean();
		case 3:
			 message=modifyUniversityDean();
		}
		
		return message;
	}
	
	public void setTabbedPane(MyTabbedPane tabbedPane) {
		this.tabbedPane=tabbedPane;
	}
	
	
	public void setAddUserPanel(JPanel addUserPanel){
		this.addUserPanel=addUserPanel;
	}
	
	
}
